//!
//! Copyright (c) 2024-2999 北京心月狐科技有限公司 All rights reserved.
//!
//! https://www.mxxshop.com
//!
//! Licensed 并不是自由软件，未经许可不能去掉 MxxShop 相关版权
//!
//! 版权所有，侵权必究！
//!

use rbatis::{crud, impl_select_page, py_sql, RBatis};
use crate::modules::product::entity::favorites_entity::Favorites;
use crate::modules::product::entity::favorites_model::QueryPageBO;


crud!(Favorites{},"mxx_product_favorites");

///检查是否已加入收藏
#[py_sql("`select count(*) from mxx_product_favorites where product_id = #{product_id} and user_id = #{user_id}`")]
pub async fn find_by_name_unique(rb: &RBatis, product_id: &Option<u64>, user_id: &Option<u64>, id: &Option<u64>) -> rbatis::Result<u64> {
    impled!()
}

// 收藏翻页
impl_select_page!(Favorites{select_by_page(dto: &QueryPageBO) =>"
    trim end=' where ':
      ` where `
      trim ' and ':
        ` and user_id = #{dto.user_id} `
    if !sql.contains('count'):
      ` order by id desc `"},"mxx_product_favorites");